package com.example.tys.baseapplication.net_tcp.protocol.tcp.ShortConnection;


import com.example.tys.baseapplication.net_tcp.frame.PacketRequest;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * Created by tys on 2019/5/5.
 */

public class MyEncoder extends MessageToByteEncoder<PacketRequest> {
    @Override
    protected void encode(ChannelHandlerContext ctx, PacketRequest msg, ByteBuf out) throws Exception {
        byte[] head = msg.getHead();
        byte[] data = msg.getData();
        System.out.println("encode: " + new String(data));
//        byte[] dest = new byte[head.length + data.length];
//        System.arraycopy(head, 0, dest, 0, head.length);
//        System.arraycopy(data, 0, dest, head.length, data.length);

        out.writeBytes(data);
    }


}
